<script type="text/javascript">
var url=global_param.context_name+"/person/search.do";
var pageNumber=1,pageSize=10;
var personId="";
$(function(){
	initDept();
	initTable();
});

function initTable(){
	var columns = [
    {
        field: '',
        title: '序号',
        switchable:false,
    	align:"center", 
    	valign:"middle",
        formatter: function (value, row, index) {
                return index+1;
        }
    },
    {
    	 field : 'personnel_id',
         v_field : 'personnel_id',
         title : '员工姓名/工号',
         align : 'center',
         valign : 'middle',
         formatter: function (value, row, index) {
             return row.personnel_name + row.personnel_shortCode;
		 }
    },
    {
        field : 'dept_name',
        v_field : 'dept_name',
        title : ' 部门名称 ',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'personnel_sex',
        v_field : 'personnel_sex',
        title : '性别',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'hotSinger',
        v_field : 'hotSinger',
        title : '是否热门歌手展示',
        align : 'center',
        valign : 'middle',
        formatter:function(value, row, index)
        {
        	if(value == "1"){
        		return "是";
        	}else{
        		return "否";
        	}
        }
    },{
        field : 'hotSingerOrder',
        v_field : 'hotSingerOrder',
        title : '展示排序',
        align : 'center',
        valign : 'middle',
        sortable : true
    },{
        field : 'action',
        title : '操作',
        align : 'center',
        valign : 'middle',
        switchable:false,
        clickToSelect:false,
        searchable:false,
        formatter:function(value, row, index)
        {
        	var html = "";
        	html += '<a href="javascript:showPersonInfo('+row.personnel_id+');" class="iconbtn btn-blue tooltip-test" data-toggle="tooltip" title="查看"><i class="zxfont icon-search"></i></a>';
        	html += '<a href="javascript:updatePersonInfo('+row.personnel_id+');" class="iconbtn btn-blue tooltip-test" data-toggle="tooltip" title="编辑"><i class="zxfont icon-edit"></i></a>';
        	return html;
        }
    }
    ];
    $('#sample_1').bootstrapTable({
        method:'POST',
        dataType:'json',
        toolbar:"#toolbar",
        contentType: "application/x-www-form-urlencoded",
        url:url,
        cache: false,
        striped: true,                              //是否显示行间隔色
        sidePagination: "server",           	//分页方式：client客户端分页，server服务端分页（*）
        pagination:true,
        sortable:true,
        sortName:"personnel_id",
        minimumCountColumns:2,
        pageNumber:pageNumber,                       //初始化加载第一页，默认第一页
        pageSize: pageSize,    //每页的记录行数（*）
        pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
        uniqueId: "personnel_id",              //每一行的唯一标识，一般为主键列
        queryParamsType:"",
        showRefresh:false,					//是否显示刷新按钮
        search:false,						//是否显示搜索框
        showToggle:false,
        ajaxOptions: {traditional: true},
        clickToSelect: true,
        onLoadSuccess: function() {
			initTabTable($("#sample_1"));
        },
        onColumnSwitch:function(){
        	initTabTable($("#sample_1"));
        },
        onClickCell:function(field,value,row){
        	if(field == "action"){
        		return;
        	}
        },
        queryParams: function queryParams(params) { //设置查询参数  
          var param = {    
        	  page: params.pageNumber,    
              pagesize: params.pageSize,
              sortname :params.sortName,
              sortorder :params.sortOrder,
              name:$("#name").val(),
              dept_name:$("#dept_name").zxCombotree('getValue'),
              hotSinger:$("#hotSinger").val()
          };
          return param;                   
        },  
        columns: columns
    });
}

function initDept(){
	$("#dept_name").zxCombotree('clear');
	$("#dept_name").val("--请选择--");
	//部门名称下拉列表初始化 
    $.ajax({
         type: "POST",
         url: global_param.context_name + "/depart/getParentDeptByOrgId.do",
         async: false,
         success: function(result) {
             var jsonStr = eval("(" + result + ")");
             $("#dept_name").zxCombotree({
                data:jsonStr,
                //宽度
                width:184,
                //不可编辑
                editable:false
            }); 
         }
     });
}

function searchUser(){
	$('#sample_1').bootstrapTable('refresh',{url: url,pageNumber: pageNumber,pageSize:pageSize});
}

function clearQueryParams(){
	$('#name').val("");
	$('#hotSinger').val("");
	initDept();
}

function queryParams()
{
 	$('#sample_1').bootstrapTable('refresh');
}

function showPersonInfo(id){
	personId = id;
	BootstrapDialog.show({
        message: $('<div id="personInfoViewDiv" class="messageDet"></div>').load('static/html/personManage/personInfoView.html'),
        title: '用户信息',
        titleClass: 'text-center',
        closable: false,
        size:BootstrapDialog.SIZE_WIDE,
        buttons: [{
            label: '关闭',
            cssClass:'btn btn-default col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
            action: function(dialog) {
//             	$("#personInfoViewDiv").html("");
                dialog.close();
            }
        }]
   });
}

function updatePersonInfo(id){
	personId = id;
	BootstrapDialog.show({
        message: $('<div id="personInfoUpdateViewDiv" class="messageDet"></div>').load('static/html/personManage/personInfoUpdateView.html'),
        title: '用户信息',
        titleClass: 'text-center',
        closable: false,
        size:BootstrapDialog.SIZE_WIDE,
        buttons: [{
            label: '保存',
            cssClass:'btn btn-primary col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
            action: function(dialog) {
            	updatePersoninfos(function(){     
	                dialog.close();
	                queryParams();
// 	            	$("#personInfoUpdateViewDiv").html("");
            	});
            }
        },{
            label: '关闭',
            cssClass:'btn btn-default col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
            action: function(dialog) {
//             	$("#personInfoUpdateViewDiv").html("");
                dialog.close();
            }
        }]
   });
}

</script>

<section class="content-header">
	<h1 class="page-name">用户管理</h1>
	<ol class="breadcrumb">
	</ol>
</section>
<section class="content item">
	 <div class="container-fluid">
		<div class="row">
			<div class="box">
        		<div class="box-body">
		            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-12">
		            	<div class="form-group">
			                <label for="name">员工姓名/工号</label>
							<input type="text" class="form-control"  id="name" style="width: 100%;" placeholder="请输入姓名/工号" >
		                </div>
		            </div>
		            <div class="col-lg-2 col-md-2 col-sm-4 col-xs-12">
		            	<div class="form-group">
		             	  <label for="dept_name">部门名称</label>
		             	  <input type="text" class="form-control" id="dept_name"/>
		                </div>
		            </div>
		            <div class="col-lg-2 col-md-2 col-sm-4 col-xs-12">
		            	<div class="form-group" >
		             	  <label for="hotSinger">是否热门歌手展示</label>
		                  <select class="form-control " id="hotSinger" name="hotSinger" >
		                  <option value="">请选择</option>
		                  <option value="1">是</option>
		                  <option value="0">否</option>
		                  </select> 
		           		</div>
		            </div>
		            <div class="col-lg-2 col-md-3 col-sm-6 col-xs-12">
		            	<div class="form-group">
		             	   <label>&nbsp;</label>
		             	   <div class="row">
							   <div class="col-xs-6">
								   <button type="button" class="btn btn-block btn-primary" onclick="searchUser()">查询</button>
							   </div>
							   <div class="col-xs-6">
								   <button type="button" class="btn btn-block btn-default" onclick="clearQueryParams()">清空</button>
							   </div>
						   </div>
					    </div>
		            </div>
		    	</div>
		   </div>
		</div>
    </div>
    
	<div class="row">
        <div class="col-xs-12">
            <div class="box box-primary">
              <div class="box-header">
                 <h3 class="box-title">数据列表</h3>
              </div>
              <div class="box-body">
              	<table id="sample_1">
                </table>
			  </div>
            </div>
         </div>
     </div>
</section>